package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Consultation;
import com.ruoyi.system.service.IConsultationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资讯管理模块Controller
 * 
 * @author ruoyi
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/system/consultation")
public class ConsultationController extends BaseController
{
    @Autowired
    private IConsultationService consultationService;

    /**
     * 查询资讯管理模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Consultation consultation)
    {
        startPage();
        List<Consultation> list = consultationService.selectConsultationList(consultation);
        return getDataTable(list);
    }

    /**
     * 导出资讯管理模块列表
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:export')")
    @Log(title = "资讯管理模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Consultation consultation)
    {
        List<Consultation> list = consultationService.selectConsultationList(consultation);
        ExcelUtil<Consultation> util = new ExcelUtil<Consultation>(Consultation.class);
        util.exportExcel(response, list, "资讯管理模块数据");
    }

    /**
     * 获取资讯管理模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:query')")
    @GetMapping(value = "/{consultationId}")
    public AjaxResult getInfo(@PathVariable("consultationId") Long consultationId)
    {
        return success(consultationService.selectConsultationByConsultationId(consultationId));
    }

    /**
     * 新增资讯管理模块
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:add')")
    @Log(title = "资讯管理模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Consultation consultation)
    {
        return toAjax(consultationService.insertConsultation(consultation));
    }

    /**
     * 修改资讯管理模块
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:edit')")
    @Log(title = "资讯管理模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Consultation consultation)
    {
        return toAjax(consultationService.updateConsultation(consultation));
    }

    /**
     * 删除资讯管理模块
     */
    @PreAuthorize("@ss.hasPermi('system:consultation:remove')")
    @Log(title = "资讯管理模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consultationIds}")
    public AjaxResult remove(@PathVariable Long[] consultationIds)
    {
        return toAjax(consultationService.deleteConsultationByConsultationIds(consultationIds));
    }
}
